package com.inspection.controller.sys;

import com.inspection.entity.SysConfigDO;
import com.inspection.model.dto.SysConfigDTO;
import com.inspection.model.dto.SysConfigQueryDTO;
import com.inspection.service.SysConfigService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
public class SysConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    @RequestMapping("/sys/config/page")
    public Wrapper<Page<SysConfigDO>> pageSysConfig(@RequestBody SysConfigQueryDTO query) {
        return Wrapper.ok(sysConfigService.pageSysConfig(query));
    }

    @SysLogAnno(operateCode =100101,operateName = "系统管理：保存")
    @RequestMapping("/sys/config/save")
    public Wrapper<String> saveSysConfig(@RequestBody SysConfigDTO save) {
        sysConfigService.saveSysConfig(save);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100102,operateName = "系统管理：更新")
    @RequestMapping("/sys/config/update")
    public Wrapper<String> updateSysConfig(@RequestBody SysConfigDTO save) {
        sysConfigService.updateSysConfig(save);
        return Wrapper.ok("ok");
    }

    @RequestMapping("/sys/config/init")
    public Wrapper<Map<String, String>> initSysConfig(@RequestBody SysConfigDTO save) {
       return  Wrapper.ok(sysConfigService.initSysConfig(save));
    }

    @RequestMapping("/sys/config/get")
    public Wrapper<SysConfigDO> getSysConfig(@RequestBody SysConfigQueryDTO query) {
        return Wrapper.ok(sysConfigService.getSysConfig(query));
    }
    @SysLogAnno(operateCode =100103,operateName = "系统管理：删除")
    @RequestMapping("/sys/config/del")
    public Wrapper<String> delSysConfig(@RequestBody SysConfigDTO del) {
        sysConfigService.delSysConfig(del);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100104,operateName = "系统管理：批量删除")
    @RequestMapping("/sys/config/batchDel")
    public Wrapper<String> batchDelSysConfig(@RequestBody SysConfigDTO del) {
        sysConfigService.batchDelSysConfig(del);
        return Wrapper.ok("ok");
    }

    @RequestMapping("/sys/config/export")
    public void exportSysConfig(@RequestBody SysConfigQueryDTO query, HttpServletResponse response) {
        sysConfigService.exportSysConfig(query, response);
    }

}
